package handler

import (
	"aiRole/internal/dto/request"
	result "aiRole/internal/dto/reslult"
	initSystem "aiRole/pkg/init"
	"github.com/gin-gonic/gin"
	"io"
)

func (h *AiHandler) Asr(c *gin.Context) {
	data, err := io.ReadAll(c.Request.Body)
	if err != nil {
		initSystem.Logger.Error(err.Error())
		c.JSON(400, gin.H{"error": "参数错误"})
		return
	}
	h.Service.Asr(c, data)
}

func (h *AiHandler) Chat(c *gin.Context) {
	req := request.UserChatRequest{}
	err := c.ShouldBindBodyWithJSON(&req)
	if err != nil {
		initSystem.Logger.Error(err.Error())
		result.Error(c, 500, "参数错误")
		return
	}
	response, err := h.Service.Chat(c, req)
	if err != nil {
		initSystem.Logger.Error(err.Error())
		result.Error(c, 500, "服务器错误")
		return
	} else {
		result.Ok(c, gin.H{"text": response})
	}
}

func (h *AiHandler) ChatV2(c *gin.Context) {
	h.Service.ChatV2(c)
}

/*
*
文本转语音接口
*/
func (h *AiHandler) TTS(c *gin.Context) {
	req := request.TTSRequestBody{}
	err := c.ShouldBindBodyWithJSON(&req)
	if err != nil {
		initSystem.Logger.Error(err.Error())
		result.Error(c, 500, "参数错误")
		return
	}
	h.Service.TTS(c, req)

}
